/*
* @Author: liqs
* @Date:   2021/10/14 15:33
 */
package pb

import (
	"encoding/json"
	"fmt"
	"github.com/Go-Server/datasource/dataset/Attribute"
	"github.com/Go-Server/datasource/dataset/feature"
	"github.com/spatial-go/geoos/space"
)

func getFeature() feature.Feature {
	f := feature.Feature{
		getAttributeInfos(),
		"featureid",
		getGeometry(),
	}
	return f
}

func getAttributeInfos() (attributeInfos Attribute.AttributeInfos) {
	attributeInfos = Attribute.AttributeInfos{}
	attributeInfo1 := Attribute.AttributeInfo{"mm1", Attribute.TypeString, 255, "test1"}
	attributeInfo2 := Attribute.AttributeInfo{"mm2", Attribute.TypeString, 255, "test2"}
	attributeInfos = Attribute.AddAttributeInfo(attributeInfos, attributeInfo1)
	attributeInfos = Attribute.AddAttributeInfo(attributeInfos, attributeInfo2)
	return attributeInfos
}

func getGeometry() (geo space.Geometry) {
	multiPoint := space.MultiPoint{{-1, 0}, {-1, 2}, {-1, 3}, {-1, 4}, {-1, 7}, {0, 1}, {0, 3},
		{1, 1}, {2, 0}, {6, 0}, {7, 8}, {9, 8}, {10, 6}}
	return multiPoint
}

func getprotoFeature() *Feature {
	f := getFeature()
	bytes, e := json.Marshal(f.Geometry)
	if e != nil {
		fmt.Printf("get Geometry failed\n")
	}
	marshal, e := json.Marshal(f.AttributeInfos)
	if e != nil {
		fmt.Printf("get AttributeInfos failed\n")
	}

	// 将 Feature 封装到 proto 文件中
	protoFeature := &Feature{
		FeatureId:      f.FeatureId,
		Geometry:       bytes,
		AttributeInfos: marshal,
	}
	return protoFeature
}
